import { getAreaObj, uploadType } from '@/utils/util'
import bus from '@/utils/eventbus'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '所属机构',
			prop: 'organizationId',
			propName: 'organizationName',
			type: 'remoteSelect',
			api: 'view_dpServiceOrgBase_page',
			filterKey: 'creditCode',
			filterLabel: 'organizationName',
			multiple: false,
			rules: [{ required: true, message: '请输入当前所属机构' }],
			span: 12,
			change: (item, form, value) => {
				if (!item.creditCode) {
					return
				}
				form.provinceId = item.provinceId
				form.provinceName = item.provinceName
				form.cityId = item.cityId
				form.cityName = item.cityName
				form.areaId = item.areaId
				form.areaName = item.areaName
				form.streetId = item.streetId
				form.streetName = item.streetName
				form.communityId = item.communityId
				form.communityName = item.communityName
				bus.emit('remote-search-params-staffId', {
					organizationId: form.organizationId || item.creditCode,
				})
			},
			control: (e, model) => {
				return {
					staffId: {
						display: e ? true : false,
					},
				}
			},
		},
		{
			label: '检测时间',
			prop: 'checkTime',
			type: 'date',
			format: 'YYYY年MM月DD日',
			valueFormat: 'YYYY-MM-DD',
			rules: [{ required: true, message: '请选择检测时间' }],
			span: 12,
		},
		{
			label: '检测人',
			prop: 'staffId',
			propName: 'staffName',
			type: 'autoSelect',
			api: 'getSecurityUserPage',
			filterKey: 'userId',
			filterLabel: 'realName',
			multiple: false,
			placeholder: '请输入名称查询选择检测人',
			paramsObj: {
				// roleName: '安全员',
			},
			span: 12,
			rules: [{ required: true, message: '请选择检测人' }],
		},
		{
			label: '巡查结果',
			prop: 'isPatrol',
			type: 'select',
			span: 12,
			rules: [{ required: true, message: '请选择巡查结果' }],
			dicData: [
				{
					label: '正常',
					value: 1,
				},
				{
					label: '异常',
					value: 2,
				},
			],
		},
		{
			label: '检测内容',
			prop: 'checkContent',
			type: 'textarea',
			maxlength: '500',
			showWordLimit: true,
			autosize: {
				minRows: 1,
			},
			span: 24,
		},
		{
			label: '检测图片',
			prop: 'checkPhoto',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			changeField: true,
			span: 24,
			rules: [{ required: true, message: '请上传检测图片' }],
		},
		{
			label: '签字照片',
			tip: '',
			prop: 'signaturePic',
			type: 'upload',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			multiple: false,
			span: 24,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '检测时间', prop: 'checkTime' },
		{
			label: '检测内容',
			prop: 'checkContent',
		},

		{
			label: '巡查结果',
			prop: 'isPatrol',
			custome: 'tag',
			dicData: [
				{
					label: '正常',
					value: 1,
					type: 'success',
				},
				{
					label: '异常',
					value: 2,
					type: 'danger',
				},
			],
		},
		{ label: '检测人', prop: 'staffName' },
		{
			label: '处理结果',
			prop: 'isHandleStatus',
			custome: 'tag',
			dicData: [
				{
					label: '未处理',
					value: 1,
					type: 'danger',
				},
				{
					label: '已处理',
					value: 2,
					type: 'success',
				},
				{
					label: '无需处理',
					value: 3,
					type: 'info',
				},
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 100,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_pbFireFighting_page',
}
export const baseConfig = {
	pageName: '消防设施全面检测记录',
	dictcodes: ['INSPECTION_CONTENT'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'checkTime',
	exportMqTopic: '/ning/export/',
	api,
	auth: {
		...api,
	},
	paramsObj: {
		source: 1,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '55%',
	},
	formConfig,
	tableConfig,
	detailConfig: formConfig,
	beforeOnLoadFormate: async (params) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(params.areas)
			resolve({
				...params,
				...areaObj,
				areas: undefined,
			})
		})
	},
	onLoadFormate: (arr: any) => {
		return new Promise((resolve, reject) => {
			resolve(
				arr.map((item) => {
					if (item.isPatrol == 1) {
						item.isHandleStatus = 3
					} else {
						item.isHandleStatus = item.isHandle
					}
					return item
				})
			)
		})
	},
}
